#include <iostream>
#include <algorithm>
using namespace std;
bool cmp(int a,int b){
    return a>b;
}
int main(){
    int Nc;
    int cpositive=0;
    cin>>Nc;
    int* coupon=new int[Nc];
    for(int i=0;i<Nc;i++){
	cin>>coupon[i];
    }
    int Np;
    int ppositive=0;
    cin>>Np;
    int* product=new int[Np];
    for(int i=0;i<Np;i++){
	cin>>product[i];
    }
    for(int i=0;i<Nc;i++){
	if(coupon[i]>0){
	    cpositive++;
	}
    }
    for(int i=0;i<Np;i++){
	if(product[i]>0){
	    ppositive++;
	}
    }
    sort(coupon,coupon+Nc,cmp);
    sort(product,product+Np,cmp);
    int result=0;
    int cnegative=Nc-cpositive;
    int pnegative=Np-ppositive;
    int pos;
    int neg;
    if(cpositive>ppositive){
	pos=ppositive;
    }else{
	pos=cpositive;
    }
    if(cnegative>pnegative){
	neg=pnegative;
    }else{
	neg=cnegative;
    }
    for(int i=0;i<pos;i++){
	result+=product[i]*coupon[i];
    }
    for(int i=0;i<neg;i++){
	result+=product[Np-1-i]*coupon[Nc-1-i];
    }
    cout<<result<<endl;
}
